/*
'  DotNetNuke -  http://www.dotnetnuke.com
'  Copyright (c) 2002-2011
'  by DotNetNuke Corporation
' 
'  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
'  documentation files (the "Software"), to deal in the Software without restriction, including without limitation 
'  the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and 
'  to permit persons to whom the Software is furnished to do so, subject to the following conditions:
' 
'  The above copyright notice and this permission notice shall be included in all copies or substantial portions 
'  of the Software.
' 
'  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 
'  TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
'  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 
'  CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
'  DEALINGS IN THE SOFTWARE.
*/

using System;
using System.Globalization;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Entities.Users;
using DotNetNuke.Services.Tokens;

namespace DotNetNuke.Modules.Store.Customer
{
    /// <summary>
    /// Summary description for OrderDetailsInfo.
    /// </summary>
    public sealed class OrderDetailInfo : IHydratable, IEquatable<OrderDetailInfo>, IPropertyAccess
    {
		#region Constructor

        public OrderDetailInfo()
		{
		}

		#endregion

        #region Private Declarations

        private int _OrderDetailID;
        private int _OrderID;
        private int _ProductID;
        private string _ModelNumber;
        private string _ModelName;
        private int _Quantity;
        private decimal _UnitCost;
        private decimal _ExtendedAmount;
        private int _RoleID;
        private string _CurrencySymbol;
        private int _Downloads;

        #endregion

        #region Public Properties

        public int OrderDetailID 
        {
            get { return _OrderDetailID; }
            set { _OrderDetailID = value; }
        }

        public int OrderID 
        {
          get { return _OrderID; }
          set { _OrderID = value; }
        }

        public int ProductID
        {
            get { return _ProductID; }
            set { _ProductID = value; }
        }

        public string ModelNumber 
        {
          get { return _ModelNumber; }
          set { _ModelNumber = value; }
        }

        public string ModelName 
        {
          get { return _ModelName; }
          set { _ModelName = value; }
        }

        public string ProductTitle
        {
          get
          {
              string title = string.Empty;
              title += _ModelNumber.Trim();
              title += title == string.Empty ? _ModelName.Trim() : " - " + _ModelName.Trim();
              return title;
          }
        }

        public int Quantity 
        {
          get { return _Quantity; }
          set { _Quantity = value; }
        }

        public decimal UnitCost 
        {
          get { return _UnitCost; }
          set { _UnitCost = value; }
        }

        public decimal ExtendedAmount 
        {
          get { return _ExtendedAmount; }
          set { _ExtendedAmount = value; }
        }

        public int RoleID 
        {
            get { return _RoleID; }
            set { _RoleID = value; }
        }

        public string CurrencySymbol
        {
            get { return _CurrencySymbol; }
            set { _CurrencySymbol = value; }
        }

        public int Downloads 
        {
            get { return _Downloads; }
            set { _Downloads = value; }
        }

        #endregion

        #region Object Overrides

        public override int GetHashCode() 
        {
            return _OrderID.GetHashCode() ^ _ProductID.GetHashCode();
        }

        #endregion

        #region IHydratable Interface

        public void Fill(System.Data.IDataReader dr)
        {
            _OrderDetailID = Convert.ToInt32(dr["OrderDetailID"]);
            _OrderID = Convert.ToInt32(dr["OrderID"]);
            _ProductID = Convert.ToInt32(dr["ProductID"]);
            _ModelNumber = Convert.ToString(Null.SetNull(dr["ModelNumber"], _ModelNumber));
            _ModelName = Convert.ToString(Null.SetNull(dr["ModelName"], _ModelName));
            _Quantity = Convert.ToInt32(dr["Quantity"]);
            _UnitCost = Convert.ToDecimal(dr["UnitCost"]);
            _ExtendedAmount = Convert.ToDecimal(dr["ExtendedAmount"]);
            _RoleID = Convert.ToInt32(Null.SetNull(dr["RoleID"], _RoleID));
            _Downloads = Convert.ToInt32(Null.SetNull(dr["Downloads"], _Downloads));
        }

        public int KeyID
        {
            get { return _OrderDetailID; }
            set { _OrderDetailID = value; }
        }

        #endregion

        #region IEquatable<OrderDetailsInfo> Interface

        public bool Equals(OrderDetailInfo other)
        {
            if (other == null)
                return false;
            return _OrderID.Equals(other.OrderID) && _ProductID.Equals(other.ProductID);
        }

        #endregion

        #region IPropertyAccess Members

        CacheLevel IPropertyAccess.Cacheability
        {
            get { return CacheLevel.fullyCacheable; }
        }

        string IPropertyAccess.GetProperty(string strPropertyName, string strFormat, CultureInfo formatProvider, UserInfo AccessingUser, Scope AccessLevel, ref bool PropertyNotFound)
        {
            string propertyValue = null;
            switch (strPropertyName.ToLower())
            {
                case "productid":
                    propertyValue = _ProductID.ToString();
                    break;
                case "modelnumber":
                    propertyValue = _ModelNumber;
                    break;
                case "modelname":
                    propertyValue = _ModelName;
                    break;
                case "producttitle":
                    propertyValue = ProductTitle;
                    break;
                case "quantity":
                    propertyValue = _Quantity.ToString();
                    break;
                case "unitcost":
                    if (formatProvider != null)
                    {
                        if (string.IsNullOrEmpty(CurrencySymbol) == false)
                            formatProvider.NumberFormat.CurrencySymbol = CurrencySymbol;
                        if (string.IsNullOrEmpty(strFormat) == false)
                            propertyValue = _UnitCost.ToString(strFormat, formatProvider.NumberFormat);
                        else
                            propertyValue = _UnitCost.ToString("C", formatProvider.NumberFormat);
                    }
                    else
                        propertyValue = _UnitCost.ToString("C");
                    break;
                case "extendedamount":
                    if (formatProvider != null)
                    {
                        if (string.IsNullOrEmpty(CurrencySymbol) == false)
                            formatProvider.NumberFormat.CurrencySymbol = CurrencySymbol;
                        if (string.IsNullOrEmpty(strFormat) == false)
                            propertyValue = _ExtendedAmount.ToString(strFormat, formatProvider.NumberFormat);
                        else
                            propertyValue = _ExtendedAmount.ToString("C", formatProvider.NumberFormat);
                    }
                    else
                        propertyValue = _ExtendedAmount.ToString("C");
                    break;
                //case "downloadlink":
                //    propertyValue = _OrderStatusID.ToString();
                //    break;
                default:
                    PropertyNotFound = true;
                    break;
            }
            return propertyValue;
        }

        #endregion
    }
}
